Finance Econometrics
Course Outline
The objective of the course is to present linear and non-linear models for both conditional mean and conditional variances. The Extreme Values Theory, Theory of Copulas and Additional Topics (Models for High Frequency Data, Continuous Time Modelsor High Dimensional Model) will also be presented.
Stylized Facts in Financial Data
Primeiro, iremos buscar as bases de dados, sendo
c("^IXIC","AAPL") o índice NASDAQ e a ação da Apple,
respectivamente:
options(scipen=999)
library(tidyquant)
library(tidyverse)
library(plotly)
library(fBasics)
library(kableExtra)
df <- tq_get(c("^BVSP","BBAS3.SA"), get = "stock.prices", from = "2016-01-01", complete_cases = FALSE)Faremos então o Retorno Simples e Retorno Composto e para o fechamento do dia (Close):
ts <- df |>
group_by(symbol) |>
summarise(date = date,
close = close ,
lClose = log(close),
rsClose = as.numeric(((close-Lag(close))/Lag(close))*100),
rcClose = as.numeric((lClose - Lag(lClose))*100)
)
pl1 <- ts |> group_by(symbol) |>
ggplot(aes(x = date, y = rsClose, color = symbol)) +
geom_line(size = 0.5) +
scale_y_continuous() +
labs(title = "Retorno Simples",
x = "", y = "Retorno", color = "") +
facet_wrap(~ symbol, nrow = 2, scales = "free_y") +
theme_tq()
ggplotly(pl1)pl2 <- ts |> group_by(symbol) |>
ggplot(aes(x = date, y = rcClose, color = symbol)) +
geom_line(size = 0.5) +
scale_y_continuous() +
labs(title = "Retorno Composto",
x = "", y = "Retorno", color = "") +
facet_wrap(~ symbol, nrow = 2, scales = "free_y") +
theme_tq()
ggplotly(pl2)O retorno simples percentual de um ativo é a variação percentual dos preços. Os retornos compostos continuamente é definido como o logarítmo da variação dos preços. As duas metodólogias de retorno são usadas para estacionarizar a série, podemos perceber que ambas cumprem seu papel além de produzir valores muito parecidos próximos do zero. Porém, a principal diferença está na propriedade do retorno composto, uma vez que basta somar os retornos dos períodos para compor o retorno acumulado.
Portanto, daqui para frente usaremos o retorno composto para análise.
Estatísticas Descritivas
Apresentamos estatísticas descritivas do retorno composto dos ativos.
tabela <- basicStats(subset(ts,symbol == "^BVSP")$rcClose)
tabela <- basicStats(subset(ts,symbol != "^BVSP")$rcClose) |> cbind(tabela)
colnames(tabela)<-c("BVSP","BBAS")
tabela |>
kbl(caption = "Estatísticas Descritivas") |>
kable_classic(full_width = F)| BVSP | BBAS | |
|---|---|---|
| nobs | 1648.000000 | 1648.000000 |
| NAs | 1.000000 | 17.000000 |
| Minimum | -23.789145 | -15.993027 |
| Maximum | 15.808076 | 13.022281 |
|
-1.262443 | -0.733494 |
|
1.431030 | 0.955177 |
| Mean | 0.067086 | 0.056579 |
| Median | 0.045353 | 0.102459 |
| Sum | 110.491267 | 92.279909 |
| SE Mean | 0.067936 | 0.041179 |
| LCL Mean | -0.066164 | -0.024190 |
| UCL Mean | 0.200337 | 0.137348 |
| Variance | 7.601488 | 2.765677 |
| Stdev | 2.757080 | 1.663033 |
| Skewness | -0.743716 | -1.268861 |
| Kurtosis | 11.434982 | 16.464816 |
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Cmd+Option+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Cmd+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.